﻿namespace Dissemination.MVC.Repositories
{
    using System.Linq;
    using System.Collections.Generic;
    using System.Web.UI.WebControls;

    using Dissemination.MVC.Models;

    using ViewModels;

    public class SeminarRepository : BaseRepository<Seminar>
    {
        public SeminarRepository()
        {
            EntityName = "Seminars";
        }

        public override List<Seminar> List()
        {
            return dataContext.Seminars.Include("TargetArea.Country").ToList();
        }

        public TargetArea GetTargetAreaByID(int targetAreaID)
        {
            return dataContext.TargetAreas.Include("Program").FirstOrDefault(ta => ta.TargetAreaID == targetAreaID);
        }

        public Seminar GetLastSeminarByTargetArea(int targetAreaID)
        {
            var seminars = (from s in dataContext.Seminars
                               where (s.TargetArea.TargetAreaID == targetAreaID)
                               orderby s.SeminarOrdinal descending
                               select s);

            return seminars.FirstOrDefault();
        }

        public Program GetProgramByTargetAreaID(int targetAreaID)
        {
            return dataContext.TargetAreas.FirstOrDefault(ta => ta.TargetAreaID == targetAreaID).Program;
        }

        public override Seminar Get(int id)
        {
            return dataContext.Seminars.Include("FollowUps.Gender").Include("FollowUps.ProfessionalBackground").Include("FollowUps.Speciality").Include("TestResults").Include("Assessments").Include("TargetArea.Country").Include("TargetArea.Program").Include("Participants.Gender").FirstOrDefault(s => s.SeminarID == id);
        }

        public List<ProfessionalBackground> GetProfessionalBackgroundsList()
        {
            return dataContext.ProfessionalBackgrounds.ToList();
        }

        public List<Speciality> GetSpecialitiesList()
        {
            return dataContext.Specialities.ToList();
        }

        public Seminar GetFollowUpReport(int id)
        {
            Seminar seminar = dataContext.Seminars.Include("FollowUps.Gender").FirstOrDefault(s => s.SeminarID == id);
            return seminar;
        }

        // TODO: Deprecated
        public ListItemCollection GetRoles()
        {
            var collection = new ListItemCollection
                                 {
                                         new ListItem("-", "1"),
                                         new ListItem("Critical care, ICU, Emergency room or recovery room", "2"),
                                         new ListItem("Donor coordinator", "3"), 
                                         new ListItem("Procurement Team: anaesthesia", "4"), 
                                         new ListItem("Procurement Team: surgery", "5"), 
                                         new ListItem("Recipients transplant coordinator", "6"),
                                         new ListItem("Others", "7")
                                 };
            return collection;
        }

        // TODO: Deprecated
        public ListItemCollection GetAttitudes()
        {
            var collection = new ListItemCollection
                                 {
                                         new ListItem("Strongly disagree", "1"),
                                         new ListItem("Somewhat disagree", "2"),
                                         new ListItem("Neither agree nor disagree", "3"),
                                         new ListItem("Somewhat agree", "4"),
                                         new ListItem("Strongly agree", "5"),
                                 };
            return collection;
        }

        // TODO: Deprecated
        //public ListItemCollection GetImprovements()
        //{
        //    var collection = new ListItemCollection
        //                         {
        //                                 new ListItem("Detection of potential organ and tissue donors ", "1"),
        //                                 new ListItem("Assessment of potential organ and tissue donors ", "2"),
        //                                 new ListItem("Brain death diagnosis knowledge", "3"),
        //                                 new ListItem("Donor management", "4"),
        //                                 new ListItem("Organizational strategies of organ and tissue procurement", "5"),
        //                                 new ListItem("Strategies for promoting donation in society", "6"),
        //                                 new ListItem("Explaining the brain death concept to the family of the donor", "7"),
        //                                 new ListItem("Suggesting organ donation and asking the family to make a decision", "8"),
        //                                 new ListItem("Supporting the donor families in their grief ", "9"),
        //                                 new ListItem("Contacting the transplant coordinator", "10"),
        //                         };
        //    return collection;
        //}

        public ListItemCollection GetConfidents()
        {
            var collection = new ListItemCollection
                                 {
                                         new ListItem("Detection of potential organ and tissue donors", "1"),
                                         new ListItem("Assessment of potential organ and tissue donors", "2"),
                                         new ListItem("Brain death diagnosis knowledge", "3"),
                                         new ListItem("Donor management", "4"),
                                         new ListItem("Organizational strategies of organ and tissue procurement", "5"),
                                         new ListItem("Strategies for promoting donation in society", "6"),
                                         new ListItem("Explaining the brain death concept to the family of the donor", "7"),
                                         new ListItem("Suggesting organ donation and asking the family to make a decision about it", "8"),
                                         new ListItem("Supporting the donor families in their grief", "9"),
                                         new ListItem("Contacting the transplant coordinator", "10"),
                                 };
            return collection;
        }

        //// TODO: Deprecated
        //public ListItemCollection GetConfortables()
        //{
        //    var collection = new ListItemCollection
        //                         {
        //                                 new ListItem("Explaining to the family the concept of brain death", "1"),
        //                                 new ListItem("Carrying out the interview to request consent for donation", "2"),
        //                                 new ListItem("Contacting the transplant coordinator", "3"),
        //                         };
        //    return collection;
        //}


        public override void Add(Seminar obj)
        {
            Seminar lastSeminar = GetLastSeminarByTargetArea(obj.TargetArea.TargetAreaID);
            int ordinal = lastSeminar == null ? 1 : lastSeminar.SeminarOrdinal + 1;
            obj.SeminarOrdinal = ordinal;
            base.Add(obj);
        }
    }
}
